package com.unit18.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unit18.dto.ProductDTO;
import com.unit18.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/product")
@CrossOrigin(origins = "*")
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping("/listProduct")
   public ResponseEntity<IPage<ProductDTO>> listProduct(@RequestBody ProductDTO queryDTO){
        IPage<ProductDTO> productDTOIPage = productService.listProduct(queryDTO);
        return ResponseEntity.ok(productDTOIPage);
    }


    @GetMapping("/deleteProduct")
    public ResponseEntity<String> deleteProduct(@RequestParam Integer id){
        productService.deleteProduct(id);
        return ResponseEntity.ok("商品删除成功");
    }

    @PostMapping("/insertProduct")
    public ResponseEntity<String> insertProduct(@RequestBody ProductDTO queryDTO){
        productService.insertProduct(queryDTO);
        return ResponseEntity.ok("商品添加成功");
    }

}
